package com.smart.builder.xml;

import java.util.List;

import javax.persistence.EntityManager;

import com.smart.hotelsmart.ListBookHotelRequestType;
import com.smart.hotelsmart.ListBookHotelResponseType;
import com.smart.hotelsmart.SummaryBookHotelType;
import com.smart.persistence.entity.BookHotel;
import com.smart.persistence.service.SmartBasicCrudDAO;
import com.smart.service.util.UtilDate;

public class BuilderListBookHotelResponseType {
	/*/# INICIO - EXERC. 2*/
	public ListBookHotelResponseType createListBookHotelResponseType(
			ListBookHotelRequestType body) {
		ListBookHotelResponseType response = new ListBookHotelResponseType();
		EntityManager em = SmartBasicCrudDAO.getInstance()
				.getEntityManagerDAO();
		List<BookHotel> list = SmartBasicCrudDAO.getInstance().consultaQueryList(em, BookHotel.class, BookHotel.findBookHotelByCustomer, body.getNumMax(), body.getOffset(), body.getCustomer());
		
		List<SummaryBookHotelType> listResp = response.getSummaryBookHotel();
		for (BookHotel bookHotel : list) {
			SummaryBookHotelType e = new SummaryBookHotelType();
			e.setNomeHotel(bookHotel.getHotel().getName());
			e.setArrival(UtilDate.createGregorianCalendar(bookHotel.getCheckIn()));
			e.setDeparture(UtilDate.createGregorianCalendar(bookHotel.getCheckOut()));
			e.setCodeBookHotel(bookHotel.getId());
			listResp.add(e);
		}
		em.close();
		return response;
	}
	// FIM - EXERC. 2 #*/

}
